/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tp2ia_partie2.objects;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 *
 * @author hp
 */
public class RegleClause extends Clause {

    public RegleClause(Set<Litteral> faits, Litteral conclution) {
        super(faits);
        Litteral conc = new Litteral(conclution.getC());
        conc.setStatutValue(true);
        Set<Litteral> f = new LinkedHashSet<Litteral>();
        for (Litteral lit : faits) {
            Litteral tmpl = new Litteral(lit.getC());
            tmpl.setStatutValue(false);
            f.add(tmpl);
        }
        f.add(conc);
        setLitteraux(f);
    }

    public RegleClause(Litteral fait, Litteral conclution) {
        super(null);
        Set<Litteral> faits = new LinkedHashSet<Litteral>();
        faits.add(fait);
        Litteral conc = new Litteral(conclution.getC());
        conc.setStatutValue(true);
        Set<Litteral> f = new LinkedHashSet<Litteral>();
        for (Litteral lit : faits) {
            Litteral tmpl = new Litteral(lit.getC());
            tmpl.setStatutValue(false);
            f.add(tmpl);
        }
        f.add(conc);
        setLitteraux(f);
    }

    @Override
    public String toString() {
        String msg = "RegleClause{ ";
        for (Litteral lit : litteraux) {
            if (lit.isNegation()) {
                msg += " " + lit + "∧  ";
            }
            if (!lit.isNegation()) {
                msg += " -> " + lit + "";
            }
        }
        return msg + " }";
    }
}
